package com.xsdl.mediator;

import javax.swing.*;
import java.awt.*;

public class CommendationPanel extends JPanel {

    private final JRadioButton rbYes = new JRadioButton("是");
    private final JRadioButton rbNo = new JRadioButton("否");
    private final JLabel lblLevel = new JLabel("表彰等级：");
    private final JTextField txtLevel = new JTextField(15);
    private final JLabel lblUnit = new JLabel("颁发单位：");
    private final JTextField txtUnit = new JTextField(15);

    private final JRadioButton rbTitleYes = new JRadioButton("是");
    private final JRadioButton rbTitleNo = new JRadioButton("否");
    private final JLabel lblTitleLevel = new JLabel("职称等级：");
    private final JTextField txtTitleLevel = new JTextField(15);
    private final JLabel lblCertNo = new JLabel("证书编号：");
    private final JTextField txtCertNo = new JTextField(15);


    public CommendationPanel() {
        super(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.anchor = GridBagConstraints.WEST;

        /* 1. 表彰区域（原有） */
        ButtonGroup bg1 = new ButtonGroup();
        bg1.add(rbYes);
        bg1.add(rbNo);

        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        add(new JLabel("是否被表彰："), gbc);
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        gbc.gridy = 1;
        add(rbYes, gbc);
        gbc.gridx = 1;
        add(rbNo, gbc);

        gbc.gridx = 0;
        gbc.gridy = 2;
        add(lblLevel, gbc);
        gbc.gridx = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1;
        add(txtLevel, gbc);

        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0;
        add(lblUnit, gbc);
        gbc.gridx = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1;
        add(txtUnit, gbc);

        /* 2. 职称证书区域（新增） */
        ButtonGroup bg2 = new ButtonGroup();
        bg2.add(rbTitleYes);
        bg2.add(rbTitleNo);

        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.gridwidth = 2;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0;
        add(new JLabel("是否有职称证书："), gbc);
        gbc.gridwidth = 1;
        gbc.gridx = 0;
        gbc.gridy = 5;
        add(rbTitleYes, gbc);
        gbc.gridx = 1;
        add(rbTitleNo, gbc);

        gbc.gridx = 0;
        gbc.gridy = 6;
        add(lblTitleLevel, gbc);
        gbc.gridx = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1;
        add(txtTitleLevel, gbc);

        gbc.gridx = 0;
        gbc.gridy = 7;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0;
        add(lblCertNo, gbc);
        gbc.gridx = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1;
        add(txtCertNo, gbc);

        /* 3. 把所有组件交给中介者统一控制 */
        new CommendationMediator(
                rbYes, rbNo, lblLevel, txtLevel, lblUnit, txtUnit,
                rbTitleYes, rbTitleNo, lblTitleLevel, txtTitleLevel, lblCertNo, txtCertNo);
    }

}